define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'need/index' + location.search,
                    add_url: 'need/add',
                    edit_url: 'need/edit',
                    del_url: 'need/del',
                    multi_url: 'need/multi',
                    import_url: 'need/import',
                    table: 'need',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'status',
                sortOrder: 'asc',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                showSearch: false,
                showToggle: false,
                showColumns: false,
                showExport: true,
                exportTypes: ['excel'],//只显示导出excel选项
                searchFormVisible:true,
                columns: [
                    [
                        {checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'users.username', title: '发布者帐号', operate: false},
                        {field: 'users.name', title: '发布者姓名', operate: false},
                        {field: 'users.phone', title: '发布者联系方式', operate: false},

                        {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        //{field: 'user_id', title: __('User_id'),operate: false},
                        //{field: 'category_ids', title: __('Category_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'company', title: __('Company'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        //{field: 'title_en', title: __('Title_en'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'company_en', title: __('Company_en'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'category.id', title: __('Category.id')},
                        {field: 'category.name', title: '分类', operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'category.name_en', title: __('Category.name_en'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'status', title: '状态',searchList: {"0":__('待审核'),"1":__('审核成功'),"2":__('审核失败')},formatter: Table.api.formatter.status},
                        {field: 'is_top', title: '是否置顶',searchList: {"0":__('否'),"1":__('是')},formatter: Table.api.formatter.status},
                        {field: 'is_white', title: '是否白名单',searchList: {"0":__('否'),"1":__('是')},formatter: Table.api.formatter.status},
                        {field: 'created_at', title: '提交时间', operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
